package net.lookyou.boot.demo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.*;
import net.lookyou.boot.demo.entity.User;
import net.lookyou.boot.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@ApiSort(1)
@Api(tags = "用户模块",value="UserController")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("test")
    @ApiOperationSupport(order = 1)
    @GetMapping(value = "/getData")
    @ResponseBody
    public String getData(){
        return "index";
    }

    @ApiOperation("通过id查询用户信息")
    @ApiOperationSupport(order = 2)
    @ApiModelProperty(value="编号",example="1")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "id", value = "用户编号", dataType = "Int", paramType = "query", required = true),
            }
    )
    @PostMapping("/user/get1")
    public User get1(int id) {

        return userService.getOne(id);
    }



    @ApiOperation("通过用户对象查询用户信息")
    @ApiResponses({ @ApiResponse(code = 200, message = "OK", response = User.class) })
    @ApiOperationSupport(order = 3, ignoreParameters = {"user.id","user.name","user.roleId"})
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "user", value = "用户对象", dataType = "User", paramType = "query", required = true, defaultValue = ""),
            }
    )
    @PostMapping(value = "/user/get2", produces = MediaType.APPLICATION_JSON_VALUE)
    public User get2(@RequestBody User user) {
        return  userService.userDetail(user);
    }


    @ApiOperation("通过用户信息返回用户列表")
    @ApiOperationSupport(order = 4)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "user", value = "用户对象", dataType = "User", paramType = "query", required = true, defaultValue = ""),
            }
    )
    @PostMapping("/user/get3")
    public List<User> get3(@RequestBody User user) {
        return  userService.selectList(user);
    }


    /**
     * QueryWrapper 分页
     */
    @ApiOperation("查询用户分页信息")
    @ApiOperationSupport(order = 5)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "pageNo", value = "页面", dataType = "Int", paramType = "query", required = true, defaultValue = "1"),
                    @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Int", paramType = "query", required = true, defaultValue = "20"),
            }
    )
    @PostMapping("/user/get4")
    public Page<User> get4(int pageNo, int pageSize) {
        return  userService.selectPage(pageNo, pageSize);
    }
}